# def getText():
#     txt = open("hamlet.txt", "r").read()
#     txt = txt.lower()
#     for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_‘{|}~':
#         txt = txt.replace(ch, " ")  # 将文本中特殊字符替换为空格
#     return txt

hamletTxt = open("hamlet.txt", "r").read()
hamletTxt = hamletTxt.lower()
s='!"#$%&()*+,-./:;<=>?@[\\]^_‘{|}~'
for ch in s:
    hamletTxt = hamletTxt.replace(ch, " ")
words = hamletTxt.split()
counts = {}  # 字典
for word in words:
    counts[word] = counts.get(word, 0) + 1
items = list(counts.items())
items.sort(key=lambda x: x[1], reverse=True)
for i in range(10):
    word = items[i][0]
    print(word)
